package com.qf.util;

/**
 * --- 就那样---
 *
 * @author zzw
 * @date 2025/8/16
 * @desc
 */

/**
 * 前后端交互的统一json类
 * 简称  R
 * 同类型的命名：ResultObject
 */
public class R {
    private  int code;
    private  String message;
    private  Object data;

    private R(){} //把构造方法隐藏
    public static R success(){
        R r = new R();
        r.setCode(200);
        r.setMessage("成功");
        return r;
    }
    public static R success(Object data){
        R r = new R();
        r.setCode(200);
        r.setMessage("成功");
        r.setData(data);  //给什么对象数据 就返回什么
        return r;
    }
    public static R error(){  //失败的方法
        R r = new R();
        r.setCode(4000);
        r.setMessage("失败");
        return r;
    }

    public static R error(int code,String message){  //失败的方法,自定义失败原因
        R r = new R();
        r.setCode(code);
        r.setMessage(message);
        return r;
    }

    @Override
    public String toString() {
        return "R{" +
                "code=" + code +
                ", message='" + message + '\'' +
                ", data=" + data +
                '}';
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }
}